//
//  FWAttentOrderController.m
//  BirdLoveSheep
//
//  Created by wwj on 16/3/11.
//  Copyright © 2016年 wwj. All rights reserved.
//

#import "FWAttentOrderController.h"
#import "FWAttentOrderCell.h"
#import "FWAttentService.h"


@interface FWAttentOrderController ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSArray *dataArray;
@end

@implementation FWAttentOrderController

static NSString * const ID = @"FWAttentOrderCell";

- (NSArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSArray array];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    [self initTableView];
    
    [self getTagsOrderData];
}

- (void)initTableView{
    UITableView *tableView = [[UITableView alloc] init];
    tableView.frame = self.view.bounds;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = [UIColor clearColor];
    tableView.rowHeight = 80;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    _tableView = tableView;
    [_tableView registerNib:[UINib nibWithNibName:NSStringFromClass([FWAttentOrderCell class]) bundle:nil] forCellReuseIdentifier:ID];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    FWAttentOrderCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

- (void)getTagsOrderData{
    FWTagsRequest *request = [[FWTagsRequest alloc] init];
    request.a = @"tag_recommend";
    request.c = @"topic";
    request.action = @"sub";
    [FWAttentService getTagsOrdeDataWith:request success:^(NSArray *response) {
        self.dataArray = response;
        [self.tableView reloadData];
    } failure:nil];
}


@end
